package cn.flc.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class SqlSessionFactoryUtil {
    //sqlsession工具类抽取
    private static SqlSessionFactory sqlSessionFactory;
    //静态块优先执行
    static {
        //加载mybatis核心文件
        InputStream resourceAsStream=null;
        try {
            resourceAsStream=Resources.getResourceAsStream("mybatis-config.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        //加载sql语句
        sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
    }
    //静态方法方便调用类名.方法 获取sqlsession
    public static  SqlSessionFactory getSqlSessionFactory(){
        return sqlSessionFactory;
    }

}
